package com.kede.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kede.dto.LayuiTableData;
import com.kede.entity.DemandInformation;
import com.kede.entity.Menu;
import com.kede.service.DemandInformationService;
import com.kede.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 求购信息 前端控制器
 * </p>
 *
 * @author 【yg】
 * @since 2020-04-02
 */
@Controller
@RequestMapping("/demand")
public class DemandInformationController {
    @Autowired
    MenuService menuService;
    @Autowired
    DemandInformationService demandservice;
    @GetMapping({"","/","/index"})
    public String index(Model model){
        List<Menu> rootMenu=menuService.getCurrentMenuListByRoleId();
        model.addAttribute("rootMenuList",rootMenu);
        return "demand/index";
    }


    @GetMapping("/list")
    public LayuiTableData list (Integer page,Integer limit){

        Page<DemandInformation> query=new Page<>();
        query.setCurrent(page);
        query.setSize(limit);


        Page<DemandInformation> pageRlt = demandservice.page(query);
        LayuiTableData data=new LayuiTableData();
        data.setData(pageRlt.getRecords());
        data.setCount(pageRlt.getTotal());

        return data;
    }
}
